﻿using Elements;
using Elements.Links;
using Elements.Shapes;
using FlowChartCanvas;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FlowChartDemo
{
    public partial class FormDemo06V1 : FormBase
    {
        public FormDemo06V1()
        {
            InitializeComponent();
            DemoTitle = "第08节随课Demo  Part1";
            DemoNote = "效果：加载画布、并添加形状、连线等。";

            //添加画布控件
            _fcc = new FCCanvasV1();
            _fcc.FCC_LinkColor += _fcc_FCC_LinkColor;
            _fcc.FCC_LinkState += _fcc_FCC_LinkState;
            _fcc.Dock = DockStyle.Fill;
            panel1.Controls.Add(_fcc);

        }

        private void _fcc_FCC_LinkState(string obj)
        {
            toolStripStatusLabel1.Text = obj;
        }

        private Color _fcc_FCC_LinkColor()
        {
            return GetColor(_linkColorIndex++);
        }

        FCCanvasV1 _fcc;

        /// <summary>
        /// 形状颜色序号
        /// </summary>
        int _shapeColorIndex = 0;
        /// <summary>
        /// 连线颜色序号
        /// </summary>
        int _linkColorIndex = 0;
               
        /// <summary>
        /// 获取不同的背景颜色
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        Color GetColor(int i)
        {
            switch (i)
            {
                case 0: return Color.Red;
                case 1: return Color.Green;
                case 2: return Color.Blue;
                case 3: return Color.Orange;
                case 4: return Color.Purple;
                default: return Color.Red;
            }
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            var rs = new RectShape()
            {
                Id = "矩形" + Guid.NewGuid().ToString(),//这里就不能用数量了，防止重复
                Rect = new Rectangle()
                {
                    X = 50,
                    Y = 50,
                    Width = 100,
                    Height = 100,
                },
                FontColor = Color.White,
                BackgroundColor = GetColor(_shapeColorIndex++),
                Text = "矩形" + _shapeColorIndex,
                TextFont = Font,

            };

            _fcc.FCC_AddShapes(new List<ShapeBase>() { rs });
            _fcc.FCC_Refresh();
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            var rs = new EllipseShape()
            {
                Id = "圆形" + Guid.NewGuid().ToString(),//这里就不能用数量了，防止重复
                Rect = new Rectangle()
                {
                    X = 50,
                    Y = 50,
                    Width = 100,
                    Height = 100,
                },
                FontColor = Color.White,
                BackgroundColor = GetColor(_shapeColorIndex++),
                Text = "圆形" + _shapeColorIndex,
                TextFont = Font,

            };
            _fcc.FCC_AddShapes(new List<ShapeBase>() { rs });
            _fcc.FCC_Refresh();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            _fcc.FCC_StartLink();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            _fcc.FCC_StopLink();
        }

    }


}
